package com.company.permission.dao;

import com.company.permission.entity.User;
import com.company.permission.mapper.UserMapper;
import com.company.permission.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserDao {

    /**
     * 任务一：查询特定用户及其拥有的所有角色
     */
    public User findUserWithRolesByUsername(String username) {
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()) {
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            return mapper.findUserWithRolesByUsername(username);
        }
    }

    /**
     * 任务三：根据条件搜索用户，并连带其角色和权限信息
     */
    public List<User> findUsersWithRolesAndMenusByCondition(String username, String email, Integer status) {
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()) {
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            return mapper.findUsersWithRolesAndMenusByCondition(username, email, status);
        }
    }
}